import type { TFunction } from 'i18next';
import { LEVEL_TYPES } from '@/utils/constants';

// 搜索数据
export const searchList = (t: TFunction): BaseSearchList[] => [
  {
    label: t('metro.typeName'),
    name: 'typeName',
    component: 'Input',
  },
  {
    label: t('metro.typeLevel'),
    name: 'typeLevel',
    component: 'Select',
    componentProps: {
      options: LEVEL_TYPES(t),
    },
  },
];

/**
 * 表格数据
 * @param t
 * @param optionRender - 渲染操作函数
 */
export const tableColumns = (t: TFunction, optionRender: TableOptions<object>): TableColumn[] => {
  return [
    {
      title: t('metro.typeName'),
      dataIndex: 'typeName',
    },
    {
      title: t('metro.typeLevel'),
      dataIndex: 'typeLevel',
      enum: LEVEL_TYPES(t),
      ellipsis: false,
    },
    {
      title: t('metro.typeSort'),
      dataIndex: 'typeSort',
    },
    {
      title: t('public.operate'),
      dataIndex: 'operate',
      width: 150,
      fixed: 'right',
      render: (value: unknown, record: object) => optionRender(value, record),
    },
  ];
};

// 新增数据
export const createList = (t: TFunction): BaseFormList[] => [
  {
    label: t('metro.typeName'),
    name: 'typeName',
    rules: FORM_REQUIRED,
    component: 'Input',
  },
  {
    label: t('metro.typeLevel'),
    name: 'typeLevel',
    rules: FORM_REQUIRED,
    component: 'RadioGroup',
    componentProps: {
      options: LEVEL_TYPES(t),
    },
  },
  {
    label: t('metro.typeSort'),
    name: 'typeSort',
    rules: FORM_REQUIRED,
    component: 'InputNumber',
  },
];
